
package linuxbox.bbs.bean;

import java.util.*;

import linuxbox.bbs.logic.*;
import linuxbox.bbs.exception.*;
import linuxbox.util.*;

public class BbsCatHome {
	private	DbAdapter m_db = null;
	private	boolean m_bTransaction = false;
	
	public BbsCatHome() {
		m_db = null;
		m_bTransaction = false;
	}
	
	public BbsCatHome(DbAdapter db) {
		m_db = db;
		m_bTransaction = true;
	}

	public void create(BbsCatKey pk) throws BbsCatBeanException {
		BbsCatBean bean = null;

		if (m_bTransaction)
			bean = new BbsCatBean(pk, m_db);
		else
			bean = new BbsCatBean(pk);
			
		bean.create();
			
		if (pk.m_iCatID == 0)
			pk.m_iCatID = bean.getCatID();
	}

	public void create(BbsCat cat) throws BbsCatBeanException {
		BbsCatBean bean = null;

		if (m_bTransaction)
			bean = new BbsCatBean(null, m_db);
		else
			bean = new BbsCatBean(null);
			
		bean.create(cat);
	}

	public void remove(BbsCatKey pk) throws BbsCatBeanException {
		BbsCatBean bean = null;

		if (m_bTransaction)
			bean = new BbsCatBean(pk, m_db);
		else
			bean = new BbsCatBean(pk);
		bean.remove();
	}

	public BbsCatKey findByKey(BbsCatKey pk) throws BbsCatBeanException {
		BbsCatBean bean = null;

		if (m_bTransaction)
			bean = new BbsCatBean(pk, m_db);
		else
			bean = new BbsCatBean(pk);

		BbsCatKey result = bean.findByKey();

		return result;
	}

	public Vector findBySql(String sqlWhere) throws BbsCatBeanException {
		BbsCatBean bean = null;

		if (m_bTransaction)
			bean = new BbsCatBean(null, m_db);
		else
			bean = new BbsCatBean(null);

		Vector result = bean.findBySql(sqlWhere);

		return result;
	}
}